import { request } from "~~/utils/fetch";
import type { Response } from "~~/types/common";
// import type { PayChannel } from "~~/types/payChannel";
import { md5 } from "js-md5";
// import { reponseIntercept } from "@/utils";
import { http } from "../utils/http";

/**
 *
 * @description 获取支付渠道列表
 */
// export const getPayChannel = (params?: any) => {
//   return request<Response<PayChannel>>({
//     url: "/pay-channel",
//     method: "post",
//     body: params,
//   }).then(reponseIntercept);
// };

export const getPayChannel = http.Post("/pay-channel");

// 获取最后一次成功支付的渠道 id
export const getPayEndSuccessID = http.Post("/pay-success-num");

// export const getPayEndSuccessID = (params?: any) => {
//   return request<Response<PayChannel>>({
//     url: "/pay-success-num",
//     method: "post",
//     body: params,
//   }).then(reponseIntercept);
// };

/**
 *
 * @description 唤起三方支付
 */
export const thirdPay = (params: any, url: string, packageId: string) => {
  return request<
    Response<{
      errors?: string;
      payUrl?: string;
    }>
  >({
    url: url,
    method: "post",
    body: params,
    headers: {
      Sign: md5(
        packageId +
          JSON.stringify(params) +
          new Date().valueOf() +
          "ksrlcd0oloyzo1zjeoikqboc5m988rwz"
      ),
    },
  });
};
